﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JukeboxParty
{
    public class Album
    {
        //
        // Properties
        //
        #region Properties
        private Artist _artist;
        public Artist AlbumArtist
        {
            get { return this._artist; }
            set { this._artist = value; }
        }

        private String _album;
        public String Name
        {
            get { return this._album; }
            set { this._album = value; }
        }

        private List<Song>  _songs;
        public List<Song> Songs
        {
            get { return this._songs; }
        }

        private String _albumArtPath;
        public String AlbumArtPath
        {
            get { return this._albumArtPath; }
            set { this._albumArtPath = value; }
        }
        #endregion

        //
        // Constructors
        //
        #region Constructors
        public Album() :
            this("__error__", null)
        {
        }

        public Album(String album, Artist artist)
        {
            this._album = album;
            this._artist = artist;
            this._songs = new List<Song>();
            artist.Albums.Add(this);
        }
        #endregion

        //
        // Member Functions
        //
        public void AddSong(String songName, int trackNumber)
        {
            // The creation of a new song will cause it to get added to the song list
            new Song(songName, this, trackNumber);
        }
        public void AddSong(Song song)
        {
            for (int i = 0; i < this._songs.Count; i++)
            {
                if (this._songs[i].TrackNumber >= song.TrackNumber)
                {
                    this._songs.Insert(i, song);
                    return;
                }
            }

            this._songs.Add(song);
        }
    }
}
